﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Message : System.Web.UI.Page
{
    string sql;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            if (Session["wj_User"] == null)
            {
                Response.Redirect("uPassport.aspx");
            }
            else
            {
                cminfo();
            }
        }
    }
    public void cminfo()
    {
        int ID = int.Parse(Request.QueryString["u_ID"]);
        sql = "select * from wj_User where wj_ID=" + ID + "";
        DataTable dt = Class1.ExecSel(sql);
        Label1.Text = dt.Rows[0]["wj_CompanyName"].ToString();
        Label2.Text = dt.Rows[0]["wj_Connecter"].ToString();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int ID = int.Parse(Request.QueryString["u_ID"]);
        sql = "select * from wj_User where wj_ID=" + ID + "";
        DataTable dt = Class1.ExecSel(sql);
        string Others = dt.Rows[0]["wj_User"].ToString();

        string title = TextBox1.Text.Trim();
        string content = TextBox2.Text.Trim();
        DateTime time = DateTime.Now;
        if (Session["wj_User"] == null)
        {
            Response.Redirect("uPassport.aspx");
        }
        else
        {
            string Own = Session["wj_User"].ToString();

            if (Others == Own)
            {
                Response.Write("<script>alert('对不起，你不能给自己留言！');window.opener=null;window.close()</script>");
            }
            else
            {
                sql = "insert into M_ly(m_Own,m_Others,m_Title,m_Content,m_Time) values('" + Own + "','" + Others + "','" + title + "','" + content + "','" + time + "')";
                Class1.ExecSql(sql);
                Response.Write("<script>alert('发送成功');window.opener=null;window.close()</script>");
            }
        }
    }
}
